class Solution(object):
    def threeSum(self, nums):
        """
https://leetcode.cn/problems/3sum/description/

给你一个整数数组 nums ，判断是否存在三元组 [nums[i], nums[j], nums[k]] 满足 i != j、i != k 且 j != k ，同时还满足 nums[i] + nums[j] + nums[k] == 0 。请

你返回所有和为 0 且不重复的三元组。

注意：答案中不可以包含重复的三元组。
        :type nums: List[int]
        :rtype: List[List[int]]
        """

        nums.sort()

        result = set()
        for j in range(1, len(nums) - 1):
            i = 0
            k = len(nums) - 1

            while i < j < k:
                current_sum = nums[i] + nums[j] + nums[k]
                if current_sum == 0:
                    result.add((nums[i], nums[j], nums[k]))
                    k = k - 1
                    i = i + 1
                elif current_sum > 0:
                    k = k - 1
                else:
                    i = i + 1

        return [list(it) for it in result]